package com.huosu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huosu.commons.constant.ConstantKey;
import com.huosu.commons.document.DownloadData;
import com.huosu.domain.Excel;
import com.huosu.domain.ClassVideo;
import com.huosu.domain.miner.*;
import com.huosu.mapper.ClassVideoMapper;
import com.huosu.mapper.MinerMapper;
import com.huosu.service.IMinerService;
import com.huosu.utils.*;
import com.huosu.vo.CacheConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author zhangjian
 * @since 2019-12-12
 */
@Service
@Slf4j
public class MinerServiceImpl extends ServiceImpl<ClassVideoMapper, ClassVideo> implements IMinerService {

	@Override
	public IPage<ClassVideo> selectPage(Integer pageCurrent, Integer pageSize, MinerQuery query) {

		Page<ClassVideo> page = new Page<ClassVideo>(pageCurrent, pageSize);

		//默认查询启用的
		if (query.getState() == null) {
			query.setState(1);
		}
		//科目
		LambdaQueryWrapper<ClassVideo> lambdaQueryWrapper = Wrappers.lambdaQuery();
		if (StringUtil.isNotEmpty(query.getSubject())) {
			lambdaQueryWrapper.eq(ClassVideo::getSubject, query.getSubject());
		}
		//阶段查询
		if (StringUtil.isNotEmpty(query.getStage())) {
			lambdaQueryWrapper.like(ClassVideo::getStage, query.getStage());
		}
		//状态
		lambdaQueryWrapper.eq(ClassVideo::getState, query.getState());

		lambdaQueryWrapper.orderByAsc(ClassVideo::getSort);
		IPage<ClassVideo> pageData = baseMapper.selectPage(page, lambdaQueryWrapper);

		return pageData;
	}
}
